#include<stdio.h>
#include <math.h>
long long mode_th(long long c,long long d , long long e)
    {
       long p=0;
       long long result=0 ;
       c%=e;
       while(d>0)
       {
        if(d%2==1)
        {
            result = (result+c)%e;  
        }
        c=(c*2)%e;
        d /=2;
       }
       return result;
    }

int main ()
{
    
    long long a,b,m;
    scanf("%lld %lld %lld",&a,&b,&m);
    printf("%lld", mode_th(a,b,m));
    return 0 ;
}